package com.ruoyi.web.controller.front;

import java.util.List;

import com.ruoyi.common.utils.UUIDFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.front.domain.SFeature;
import com.ruoyi.front.service.ISFeatureService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 首页文章Controller
 * 
 * @author jyp
 * @date 2021-07-22
 */
@Controller
@RequestMapping("/front/feature")
public class SFeatureController extends BaseController
{
    private String prefix = "front/feature";

    @Autowired
    private ISFeatureService sFeatureService;

    @RequiresPermissions("front:feature:view")
    @GetMapping()
    public String feature()
    {
        return prefix + "/feature";
    }

    /**
     * 查询首页文章列表
     */
    @RequiresPermissions("front:feature:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SFeature sFeature)
    {
        startPage();
        List<SFeature> list = sFeatureService.selectSFeatureList(sFeature);
        return getDataTable(list);
    }

    /**
     * 导出首页文章列表
     */
    @RequiresPermissions("front:feature:export")
    @Log(title = "首页文章", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SFeature sFeature)
    {
        List<SFeature> list = sFeatureService.selectSFeatureList(sFeature);
        ExcelUtil<SFeature> util = new ExcelUtil<SFeature>(SFeature.class);
        return util.exportExcel(list, "feature");
    }

    /**
     * 新增首页文章
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }



    @GetMapping("/addFeature")
    public String addMenuInfo(String id, ModelMap mmap)
    {
        mmap.put("id", id);
        return prefix + "/addFeature";
    }

    /**
     * 新增保存首页文章
     */
    @RequiresPermissions("front:feature:add")
    @Log(title = "首页文章", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SFeature sFeature)
    {
        sFeature.setId(UUIDFactory.getStringId());
        return toAjax(sFeatureService.insertSFeature(sFeature));
    }

    /**
     * 修改首页文章
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        SFeature sFeature = sFeatureService.selectSFeatureById(id);
        mmap.put("sFeature", sFeature);
        return prefix + "/edit";
    }

    /**
     * 修改保存首页文章
     */
    @RequiresPermissions("front:feature:edit")
    @Log(title = "首页文章", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SFeature sFeature)
    {
        return toAjax(sFeatureService.updateSFeature(sFeature));
    }

    /**
     * 删除首页文章
     */
    @RequiresPermissions("front:feature:remove")
    @Log(title = "首页文章", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sFeatureService.deleteSFeatureByIds(ids));
    }
}
